//
//  HNSH_ApplyRefundImageCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_ApplyRefundImageCell.h"

@interface HNSH_ApplyRefundImageCell ()
@property (nonatomic, strong)UIImageView * imgView;
@property (nonatomic, strong)UIButton * delBtn;
@end

@implementation HNSH_ApplyRefundImageCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

#pragma mark - Cycle Methods
- (void)addAllViews{
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.delBtn];
}

- (void)addAllLayout{
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.contentView);
    }];
    [self.delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.imgView.mas_right);
        make.width.height.mas_equalTo(18);
        make.centerY.mas_equalTo(self.imgView.mas_top);
    }];
}

- (void)setImage:(UIImage *)image{
    _image = image;
    
    if (image) {
        self.delBtn.hidden = NO;
        self.imgView.image = image;
    } else {
        self.delBtn.hidden = YES;
        self.imgView.image = [UIImage imageNamed:@"mine_order_apply_refund_add"];;
    }
}

- (void)setImageString:(NSString *)imageString{
    _imageString = imageString;
    if (imageString) {
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:imageString]];
    } else {
        self.imgView.image = [UIImage imageNamed:@"mine_order_apply_refund_add"];
    }
}

#pragma mark - Myself Methods
- (void)delBtnAction:(UIButton *)sender{
    if (self.deletePhotoBlock) {
        self.deletePhotoBlock(self);
    }
}

#pragma mark - Setter Methods
- (void)setIsShowDelBtn:(BOOL)isShowDelBtn{
    self.delBtn.hidden = !isShowDelBtn;
}

#pragma mark - Lazy Methods
- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
        _imgView.userInteractionEnabled = YES;
        _imgView.image = [UIImage imageNamed:@"mine_order_apply_refund_add"];
    }
    return _imgView;
}

- (UIButton *)delBtn{
    if (!_delBtn) {
        _delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_delBtn setImage:[UIImage imageNamed:@"mine_order_apply_refund_delete"] forState:UIControlStateNormal];
        [_delBtn addTarget:self action:@selector(delBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        _delBtn.hidden = YES;
    }
    return _delBtn;
}

@end
